<?php
namespace Index\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function indexAction(){
		/**
		 * 问题列表
		 */
    	$Question = M('Question'); 
		$count    = $Question->count();
		$Page  = new \Think\Page($count,5);
		$show  = $Page->show();
    	$model = M();
    	$sql = "select t1.id,t1.uid,t1.title,t1.views,t1.create_time,t2.turename,t2.face_url from question t1 left join user t2 on t1.uid=t2.id order by create_time desc limit {$Page->firstRow},{$Page->listRows}";
    	$questionData = $model->query($sql);
//		var_dump($questionData);
    	$this->assign('page',$show);
    	$this->assign('questionData',$questionData);


		/**
		 * 热门话题
		 */
		$model = M();
		$sql = "select t1.id,t1.uid,t1.title,t1.attention,t2.face_url from question t1 left join user t2 on t1.uid = t2.id order by attention desc limit 5";
		$hot = $model->query($sql);
		$this->assign('hot',$hot);
//		var_dump($hot);



		/**
		 * 热门用户
		 */
		$model = M();
		$sql = "select t2.username,t2.face_url,t1.uid,t2.id from answer t1 left join user t2 on t1.uid = t2.id group by t1.uid order by uid desc limit 5";
		$user = $model->query($sql);
		$this->assign('user',$user);
//		var_dump($user);

		$this->display('index');
    }

  //   public function showAction(){
  //   	$Question = M('Question'); 
		// $count    = $Question->count();

		// $Page  = new \Think\Page($count,1);

		// $show  = $Page->show();

		// $questionData = $Question->order('create_time')->limit($Page->firstRow.','.$Page->listRows)->select();
		// $this->assign('questionData',$questionData);

		// $this->assign('page',$show);

		// $this->display(); 
  //   }





}













